package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.pojo.CapitalItem;
import com.yh.homestay.service.CapitalItemService;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.common.ItemEditResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品管理
 */
@Controller
public class CapitalItemController {
    @Autowired
    private CapitalItemService capitalItemService;

    /**
     * 展示所有商品
     *
     * @param
     * @return
     */
    @RequestMapping("/item/show")
    @ResponseBody
    @SystemLog(methods="商品展示", module = "商品管理")
    public HomeStayResult findCapitalItemAll(Integer page, Integer limit, String itemName) {

        return capitalItemService.findAll(page,limit,itemName);
    }

    /**
     * 添加商品
     */
    @RequestMapping("/item/add")
    @ResponseBody
    @SystemLog(methods="添加商品", module = "商品管理")
    public HomeStayResult addCapitalItem(CapitalItem capitalItem) {
        return capitalItemService.addCapitalItem(capitalItem);
    }

    /**
     * 去修改商品信息
     */
    @RequestMapping("/item/goEdit/{id}")
    @ResponseBody
    public ItemEditResult goEditCapitalItem(@PathVariable(value = "id") Integer id) {
        return capitalItemService.findItemById(id);
    }

    /**
     * 提交修改
     */
    @RequestMapping("/item/edit")
    @ResponseBody
    @SystemLog(methods="修改商品", module = "商品管理")
    public HomeStayResult editCapitalItem(CapitalItem capitalItem) {
        return capitalItemService.editCapitalItem(capitalItem);
    }

    /**
     * 删除
     */
    @RequestMapping("/item/del/{id}")
    @ResponseBody
    @SystemLog(methods="删除商品", module = "商品管理")
    public HomeStayResult delCapitalItem(@PathVariable Integer id) {
        return capitalItemService.delCapitalItem(id);
    }


    /**
     * 批量删除
     */
    @RequestMapping(value = "/item/batchDel", method = {RequestMethod.POST})
    @ResponseBody
    @SystemLog(methods="删除商品", module = "商品管理")
    public HomeStayResult batchDelCapitalItem(@RequestParam List<Integer> ids) {
        return capitalItemService.batchDelCapitalItem(ids);
    }

}
